﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using BCNPCObject.DB;
using DbLinq;
using DbLinq.Oracle;
using CMISLibrary.Entities;
using CMISLibrary;

namespace BCNPCObject.THONGTIN_KHANG
{
    public class cls_HDG_VITRI_DDO_Controller
    {
        #region   Atributes

        //private DataSet CMIS_Header = new CMISOutputParameter();
        private HDG_VITRI_DDO info;

        #endregion

        #region   Constructor

        public cls_HDG_VITRI_DDO_Controller()
        {
            info = new HDG_VITRI_DDO();
        }
        public cls_HDG_VITRI_DDO_Controller(HDG_VITRI_DDO Info)
        {
            this.info = Info;
        }

        #endregion

        #region   Properties

        public HDG_VITRI_DDO pInfor
        {
            get { return info; }
            set { info = value; }
        }

        #endregion

        #region Methods
        public bool insert_HDG_VITRI_DDO(ref Int64 id_vitri_ddo, ref string maloi)
        {
            long _ID = CMIS2.DB.ExecuteCommand("Select SEQ_HDG_VITRI_DDO.NEXTVAL from dual");
            if (_ID == -1) return false;
            try
            {
                info.ID_VITRI_DDO = Convert.ToInt64(_ID);
                HDG_VITRI_DDO objHDG_VITRI_DDO = new HDG_VITRI_DDO()
                {
                    MA_DVIQLY = info.MA_DVIQLY,
                    ID_VITRI_DDO = info.ID_VITRI_DDO,
                    NGAY_HLUC = info.NGAY_HLUC,
                    MA_DDO = info.MA_DDO,
                    MA_TRAM = info.MA_TRAM,
                    MA_LO = info.MA_LO,
                    MA_TO = info.MA_TO,
                    PHA = info.PHA,
                    SO_COT = info.SO_COT,
                    SO_HOM = info.SO_HOM,
                    MA_CNANG = info.MA_CNANG,
                    NGAY_TAO = info.NGAY_TAO,
                    NGUOI_TAO = info.NGUOI_TAO,
                    NGAY_SUA = info.NGAY_SUA,
                    NGUOI_SUA = info.NGUOI_SUA
                };
                CMIS2.DB.HDG_VITRI_DDO.InsertOnSubmit(info);
                CMIS2.DB.SubmitChanges();
                id_vitri_ddo = _ID;
                CMIS2.ResetDB();
                return true;
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB();
                return false;
            }
        }
        public bool delete_HDG_VITRI_DDO(DataTable dt, ref string maloi)
        {
            try
            {
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        var query = from p in CMIS2.DB.HDG_VITRI_DDO
                                    where (p.MA_DVIQLY == dt.Rows[i]["MA_DVIQLY"].ToString() && p.ID_VITRI_DDO == Convert.ToInt64(dt.Rows[i]["ID_VITRI_DDO"]))
                                    select p;
                        if (query != null && query.Count() > 0)
                        {
                            CMIS2.DB.HDG_VITRI_DDO.DeleteAllOnSubmit(query.ToList());
                            CMIS2.DB.SubmitChanges();
                        }
                    }
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                maloi = ex.ToString();
                CMIS2.ResetDB(); return false;
            }
        }
        #endregion
    }
}
